class Node {
  constructor(val, next = null) {
    this.val = val;
    this.next = next;
  }
}


function ListNode() {
  let head = new Node(1);
  head.next = new Node(2);
  head.next.next = new Node(3);
  head.next.next = new Node(4);

  return head;
}

let nodeList = ListNode();
console.log('nodeList:',nodeList);

let p = nodeList, ret = '';
while (p){
  ret += `${p.val}->`;
  p = p.next;
}
ret += 'null';
console.log(ret);


//---

// 双数组
function ListNode(){
  const data = []; //用来存储数据
  const next = []; //用来存储指针

  function addNode(ind, p, val){
    next[p] = next[ind];
    next[ind] = p;
    data[p] = val;
  }
}
